﻿using Nomo.UnityCoreModule;

namespace Nomo.UnityEditorModule
{
    internal class RectTransformViewerWindow : UnityEditor.EditorWindow
    {
        private const string Name = "矩形变换查看器";

        private UnityEngine.RectTransform _rectTransform;

        [UnityEditor.MenuItem(nameof(CoreModule.Nomo) + "/" + Name)]
        private static void Open()
        {
            GetWindow<RectTransformViewerWindow>(Name);
        }

        private void OnGUI()
        {
            if (UnityEngine.GUILayout.Button("刷新"))
            {
                _rectTransform = UnityEditor.Selection.activeTransform as UnityEngine.RectTransform;
            }

            if (_rectTransform != null)
            {
                UnityEditor.EditorGUILayout.Vector2Field(nameof(UnityEngine.RectTransform.anchorMin),        _rectTransform.anchorMin);
                UnityEditor.EditorGUILayout.Vector2Field(nameof(UnityEngine.RectTransform.anchorMax),        _rectTransform.anchorMax);
                UnityEditor.EditorGUILayout.Vector2Field(nameof(UnityEngine.RectTransform.anchoredPosition), _rectTransform.anchoredPosition);
                UnityEditor.EditorGUILayout.Vector2Field(nameof(UnityEngine.RectTransform.sizeDelta),        _rectTransform.sizeDelta);
                UnityEditor.EditorGUILayout.Vector2Field(nameof(UnityEngine.RectTransform.pivot),            _rectTransform.pivot);
                UnityEditor.EditorGUILayout.Vector4Field(nameof(UnityEngine.RectTransform.localRotation), (UnityEngine.Vector4) (Float4) _rectTransform.localRotation);
                UnityEditor.EditorGUILayout.Vector3Field(nameof(UnityEngine.RectTransform.localScale), _rectTransform.localScale);
            }
            else
            {
                UnityEditor.EditorGUILayout.LabelField("选择一个带有矩形变换的游戏物体，然后点击“刷新”按钮");
            }
        }
    }
}
